package formater

type EncodeFunc func(src []byte) string

type DecodeFunc func(s string) ([]byte, error)

type Formater interface {
	Encode(src []byte) string
	Decode(s string) ([]byte, error)
	Name() string
}

type formater struct {
	encodeFunc EncodeFunc
	decodeFunc DecodeFunc
	name       string
}

func NewFormater(name string, encodeFunc EncodeFunc, decodeFunc DecodeFunc) Formater {
	return &formater{
		encodeFunc: encodeFunc,
		decodeFunc: decodeFunc,
		name:       name,
	}
}

func (f *formater) Encode(src []byte) string {
	return f.encodeFunc(src)
}

func (f *formater) Decode(s string) ([]byte, error) {
	return f.decodeFunc(s)
}

func (f *formater) Name() string {
	return f.name
}
